/*
 * Copyright 2014 Jonathan Haas
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package app.grinreader.model;

import android.graphics.Typeface;
import org.xmlpull.v1.XmlPullParser;

import java.util.HashMap;
import java.util.Map;

/**
 *
 */
public class Styles {
	private static final Map<String, StyleElement> styles = new HashMap<>();

	static {
		StyleElement bold = new StyleElement();
		StyleElement italic = new StyleElement();
		StyleElement superscript = new StyleElement();
		StyleElement subscript = new StyleElement();
		StyleElement heading1 = new StyleElement();
		StyleElement heading2 = new StyleElement();
		StyleElement heading3 = new StyleElement();
		StyleElement heading4 = new StyleElement();
		StyleElement heading5 = new StyleElement();
		StyleElement heading6 = new StyleElement();
		StyleElement paragraph = new StyleElement();
		StyleElement center = new StyleElement();

		bold.setTextStyle(Typeface.BOLD);

		italic.setTextStyle(Typeface.ITALIC);

		superscript.setTextScale(.71f);
		superscript.setBaselineOffset(.57f);

		subscript.setTextScale(.71f);
		subscript.setBaselineOffset(-.21f);

		heading1.setTextScale(1.8f);
		heading1.setTextStyle(Typeface.BOLD);
		heading1.setPageBreak(true);
		heading1.setMarginBottom(.81f);
		heading1.setCentered(true);

		heading2.setTextScale(1.6f);
		heading2.setTextStyle(Typeface.BOLD);
		heading2.setPageBreak(true);
		heading2.setMarginBottom(.61f);
		heading2.setCentered(true);

		heading3.setTextScale(1.2f);
		heading3.setTextStyle(Typeface.BOLD);
		heading3.setMarginTop(.6f);
		heading3.setMarginBottom(.3f);

		heading4.setTextScale(1.1f);
		heading4.setTextScaleX(1.3f);
		heading4.setMarginTop(.6f);
		heading4.setMarginBottom(.3f);

		heading5.setTextScale(.8f);
		heading5.setTextScaleX(1.5f);
		heading5.setMarginTop(.6f);
		heading5.setMarginBottom(.3f);

		heading6.setTextScale(.8f);
		heading6.setTextScaleX(1.5f);
		heading6.setMarginTop(.6f);
		heading6.setMarginBottom(.3f);

		paragraph.setTextIndent(1.2f);

		center.setCentered(true);

		styles.put("b", bold);
		styles.put("strong", bold);
		styles.put("i", italic);
		styles.put("em", italic);
		styles.put("h1", heading1);
		styles.put("h2", heading2);
		styles.put("h3", heading3);
		styles.put("h4", heading4);
		styles.put("h5", heading5);
		styles.put("h6", heading6);
		styles.put("sup", superscript);
		styles.put("sub", subscript);
		styles.put("p", paragraph);
		styles.put("center", center);
	}

	public StyleElement forHtml(XmlPullParser parser) {
		return styles.get(parser.getName());
	}
}
